const jsonServer = require('json-server');
const log = require("log-output-color");
const path = require('path');
const server = jsonServer.create();
const dataFilePath = path.join(__dirname, 'db.json'); // 指定 JSON 数据文件路径
const router = jsonServer.router(dataFilePath);
const middlewares = jsonServer.defaults();
const requstConfig = require('../api/request.js')

const port = requstConfig.port || 5555;
const fixUrl = '/';

const json = require('./db.json')

log.data('Resources\n')
Object.keys(json).map(name =>{
    log.data(`http://localhost:${port}${fixUrl}${name}`);
})

server.use(middlewares);
// 将 /api 前缀添加到路由
server.use(fixUrl, router);

server.listen(port, () => {
  log.silly('\n{^_^}/ hi!\n');
  log.text(`请访问: http://localhost:${port}${fixUrl}`);
});